package com.jxnu.duewang.zmly.zhangHaoQi;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.jxnu.duewang.zmly.R;
import com.squareup.picasso.Picasso;

import java.util.List;

import rx.internal.operators.NeverObservableHolder;

/**
 * Created by lenovo on 2016/12/6.
 */

public class RecyclerviewAdapter extends RecyclerView.Adapter<RecyclerviewAdapter.ViewHolder>{
    private static final int ITEM_VIEW_TYPE_HEADER = 0;
    private static final int ITEM_VIEW_TYPE_ITEM = 1;
    private List<Classify> list;
    private List<Bottomimage> bottomlist;
    private Context context;

    public RecyclerviewAdapter(List<Classify> list, Context context) {
        this.list = list;
        this.context = context;
    }
    public boolean isHeader(int position){
        return position==0;
    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (viewType == ITEM_VIEW_TYPE_HEADER) {
            return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.zhqheaderlayout, parent, false));
        }else {
            return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.zhqgirdlayout,parent,false));
        }
    }
    public void setviewpagerlist(List<Bottomimage> bottomlist){
         this.bottomlist=bottomlist;
    }
    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        if(isHeader(position)){
            Picasso.with(context).load(list.get(position).getCoverPath()).into(holder.imageView2);
        }else {
            Picasso.with(context).load(list.get(position).getCoverPath()).into(holder.imageView1);
            holder.textView.setText(list.get(position).getTitle());
        }
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    @Override
    public int getItemViewType(int position) {
        return isHeader(position)?ITEM_VIEW_TYPE_HEADER:ITEM_VIEW_TYPE_ITEM;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{
         private TextView textView;
         private ImageView imageView1,imageView2;
         private ViewPager viewPager;
         public ViewHolder(View itemView) {
             super(itemView);
             textView= (TextView) itemView.findViewById(R.id.zhqgridlayouttext);
             imageView1= (ImageView) itemView.findViewById(R.id.zhqgirldllayoutimage);
             imageView2= (ImageView) itemView.findViewById(R.id.zhqhaederlayoutimage);
             viewPager= (ViewPager) itemView.findViewById(R.id.zhqfootviewpager);
         }
     }
    public static class HeaderHolder extends RecyclerView.ViewHolder{

        public HeaderHolder(View itemView) {
            super(itemView);
        }
    }
}
